package pkg.lbmg.org;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

public class Utils {

	// GAME STATES
    public final static int CREATED         = 0;
    public final static int WAITING_PLAYERS = 1;
    public final static int SPREAD          = 2;
    public final static int STARTED         = 3;
    public final static int ENDED           = 4;
    public final static int RESULTS         = 5;
    
    
    // PLAYER STATES
    public final static int H_NO_POWER			= 0;
    public final static int H_RADAR				= 1;
    public final static int H_JAMMER			= 2;
    public final static int H_SEND_RANDOM_ACT   = 3;
    public final static int H_GET_RANDOM_ACT    = 4;
    public final static int H_THREAT_DETECTOR	= 5;
    public final static int H_DECOY				= 6;
    public final static int H_END_GAME			= 100;
    
    public final static int A_NO_POWER			= 10;
    public final static int A_RADAR				= 11;
    public final static int A_JAMMER_SHIELD		= 12;
    public final static int A_TELEPATHIC_AID    = 13;
    public final static int A_PROXIMITY_SENSOR	= 14;
    public final static int A_SNEAKY_MOVE		= 15;
    public final static int A_FALSE_ALARM		= 16;
    public final static int A_JAMMED			= 19;
    public final static int A_END_GAME			= 200;
    
    // CAPTURE STATES
    public final static int H_NO_CAPTURE		= 0;
    public final static int H_BEING_CAPTURED	= 1;
    public final static int H_JUST_CAPTURED		= 2;
    public final static int H_JUST_ESCAPED		= 3;
    
    public final static int A_NO_CAPTURE		= 10;
    public final static int A_CAPTURING			= 11;
    public final static int A_JUST_CAPTURED		= 12;
    public final static int A_JUST_ESCAPED		= 13;
    
    // THREAD CONTROL
    public final static int UPDATE_SCORE_TIME		= 0;
    public final static int UPDATE_RBTN_STATE_ON	= 1;
    public final static int UPDATE_RBTN_STATE_OFF	= 2;
    public final static int UPDATE_LBTN_STATE_ON	= 3;
    public final static int UPDATE_LBTN_STATE_OFF	= 4;
    public final static int UPDATE_CLEAN_OVERLAYS	= 5;
    public final static int UPDATE_UI_JAM_ON		= 6;
    public final static int UPDATE_UI_JAM_OFF		= 7;
    public final static int UPDATE_UI_RADAR_1		= 8;
    public final static int UPDATE_UI_RADAR_2		= 9;
    public final static int UPDATE_UI_JUST_CAPTURED	= 10;
    
    public final static int MSG_H_CAPTURING			= 30;
    public final static int MSG_H_CAPTURED			= 31;
    public final static int MSG_H_ESCAPED			= 32;
    public final static int MSG_A_CAPTURING			= 33;
    public final static int MSG_A_CAPTURED			= 34;
    public final static int MSG_A_ESCAPED			= 35;
    public final static int MSG_H_JAMMER			= 36;
    public final static int MSG_H_JAMMER_NOT		= 37;
    public final static int MSG_B_RADAR_NOT			= 38;
    
    public static Place[] globalPlaces = new Place[100];
    
 
	public static void showToastShort(Context base, String p) {
		Toast toast = Toast.makeText(base, p, Toast.LENGTH_SHORT);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.show();
	}
	
	public static void showTopToastShort(Context base, String p) {
		Toast toast = Toast.makeText(base, p, Toast.LENGTH_SHORT);
		toast.setGravity(Gravity.TOP, 0, 20);
//		toast.setMargin(30, 30);
		toast.show();
	}
	
	public static String md5Hash(String s) throws NoSuchAlgorithmException {
		
		   MessageDigest m = MessageDigest.getInstance("MD5");
		   m.update(s.getBytes(),0,s.length());
		   String hash = new BigInteger(1,m.digest()).toString(16);

		   return hash;
		}

}
